﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HT.Data.BussinessLogic;
using HT.Data.Objects;
using HT.Data.Util;
using System.Data.SqlTypes;
using System.Text;
namespace Hotel.Operations
{
    public partial class BookingStatus : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // HT.Data.Cookie ck;
            if (!IsPostBack)
            {
                //ck = new HT.Data.Cookie();
                //ck.GetCookie("HotelCookie");
                //  LoadHotelList();
                txtStartDate.Text = DateTime.Now.Date.AddDays(1).ToString("MM/dd/yyyy");
                txtEndate.Text = DateTime.Now.Date.AddDays(1).ToString("MM/dd/yyyy");
                LoadRoomType();
                GetBookingStatus();
            }
        }


        //public void LoadHotelList()
        //{
        //    //ddlHotel.DataSource = HotelManger.GetInstance().GetAllHotel();
        //    //ddlHotel.DataTextField = "HotelName";
        //    //ddlHotel.DataValueField = "HotelId";

        //    //ddlHotel.DataBind();

        //}

        public void LoadRoomType()
        {
            ddlRoomType.DataSource = HotelManger.GetInstance().GetAllRoomType(0, 0);
            ddlRoomType.DataValueField = "RoomTypeId";
            ddlRoomType.DataTextField = "RoomType";
            ddlRoomType.DataBind();
            ddlRoomType.Items.Insert(0, new ListItem("All", "0"));

        }

        public void GetBookingStatus()
        {
            int roomid = (ddlRoomType.SelectedValue == "") ? 0 : Convert.ToInt32(ddlRoomType.SelectedValue);
            GridStatus.DataSource = HotelManger.GetInstance().GetAllBooking(txtStartDate.Text, txtEndate.Text, 0, roomid);
            GridStatus.DataBind();

        }

        protected void GridStatus_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (((HyperLink)e.Row.FindControl("hypBooked")).Text.Trim() == "0")
                {
                    ((HyperLink)e.Row.FindControl("hypBooked")).Enabled = false;
                }
                if (((HyperLink)e.Row.FindControl("hypAvailable")).Text.Trim() == "0")
                {
                    ((HyperLink)e.Row.FindControl("hypAvailable")).Enabled = false;
                }

            }

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                GetBookingStatus();
            }
            catch (Exception ex)
            {
                StringBuilder objStringBuilder = new StringBuilder();
                objStringBuilder.Append("<script language='javascript'>");
                objStringBuilder.Append("alert('" + ex.Message + "')");
                objStringBuilder.Append("</script>");
                Page.RegisterStartupScript("ClientScript", objStringBuilder.ToString());
                //TODO:
                //Response.Write("<script type='text/javascript'>alert('" + ex.Message + "') </script>");
            }

        }


    }
}